package com.hongx.zhibo;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hongx.zhibo.utils.MagicTextView;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LiveAdapter extends RecyclerView.Adapter<ViewHolder> {

    private final Context context;
    private final List<ItemBean> data;
    private final TranslateAnimation inAnim;
    private final TranslateAnimation outAnim;

    public LiveAdapter(Context context, List<ItemBean> data) {
        this.context = context;
        this.data = data;
        inAnim = (TranslateAnimation) AnimationUtils.loadAnimation(context, R.anim.gift_in); // 礼物进入时动画

        outAnim = (TranslateAnimation) AnimationUtils.loadAnimation(context, R.anim.gift_out); // 礼物退出时动画
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return ViewHolder.createViewHolder(context, parent, R.layout.item_gift);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return 0;
    }


    public static class LiveItemViewDelegate implements ItemViewDelegate<ItemBean> {
        @Override
        public int getItemViewLayoutId() {
            return R.layout.item_gift;
        }

        @Override
        public boolean isForViewType(ItemBean item, int position) {
            return item.type == 1 | item.type == 0;
        }

        @Override
        public void convert(ViewHolder holder, ItemBean itemBean, int position) {

            if (itemBean.type == 0) {
                holder.getView(R.id.root_layout).setVisibility(View.INVISIBLE);
                return;
            }
            holder.getView(R.id.root_layout).setVisibility(View.VISIBLE);
            ImageView gitview = holder.getView(R.id.iv_gift);
            gitview.setImageResource(itemBean.gifId);
            MagicTextView mv = holder.getView(R.id.mtv_giftNum);
            mv.setText("x" + itemBean.count);
        }
    }

}
